package yourapp.expense.util;

import java.sql.Date;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.List;

public class DateListUtil {
  public static List<java.sql.Date> getDateList(int weekOption) {
    List<java.sql.Date> dates = new ArrayList<>();
    LocalDate today = LocalDate.now();
    LocalDate start;

    switch (weekOption) {
      case 1:
        start = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
        break;
      case 2:
        start = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY))
            .minusWeeks(1);
        break;
      case 3:
        start = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY))
            .minusWeeks(2);
        break;
      default:
        return dates;
    }

    for (int i = 0; i < 7; i++) {
      LocalDate localDate = start.plusDays(i);
      dates.add(java.sql.Date.valueOf(localDate));
    }
    return dates;
  }
}